package jmcnet.libcommun.communs.errormanager
{
	import flash.utils.Dictionary;
	
	import jmcnet.libcommun.communs.enum.EnumBase;
	import jmcnet.libcommun.communs.exceptions.ErrorIllegalEnumValue;
	
	import mx.collections.ArrayCollection;
	
	public class EnumTypeError extends EnumBase
	{
		/**
		 * Les valeurs possibles 
		 */
		public static const TYPE_Erreur:EnumTypeError = new EnumTypeError("Erreur");
		public static const TYPE_Warning:EnumTypeError = new EnumTypeError("Warning");
		public static const TYPE_Info:EnumTypeError = new EnumTypeError("Info");
		
		public static function init():Boolean {
			addPossibleValue("TYPE_Erreur",TYPE_Erreur );
			addPossibleValue("TYPE_Warning",TYPE_Warning );
			addPossibleValue("TYPE_Info",TYPE_Info );
			return true;
		}
		
		public function EnumTypeError(value:String) {
			super(value);
		}
		
		/**********************************************************************************************************************
		 * Partie commune a tous les Enum
		 */
		private static var _values:Dictionary = new Dictionary();
		private static var _literals:ArrayCollection = new ArrayCollection();
		private static var _names:ArrayCollection = new ArrayCollection();
		private static var _valueList:ArrayCollection = new ArrayCollection();
		
		static private const res:Boolean = init();
		
		/**
		 * Ajoute une valeur possible a cet �num�r� 
		 */
		public static function addPossibleValue(name:String, possibility:EnumBase):void {
			_values[possibility.value] = possibility;
			_valueList.addItem(possibility);
			_literals.addItem(possibility.value);
			_names.addItem(name);
		}
		
		public static function fromString(value:String):EnumTypeError {
			var typeValue:EnumTypeError = _values[value];
			if (typeValue == null)
			{
				throw new ErrorIllegalEnumValue("invalid value '" + value + "', possible values are: " + _literals);
			}
			return typeValue;
		}
		
		public static function literals():ArrayCollection { return _literals; }
		public static function names():ArrayCollection { return _names; }	    
		public static function values():ArrayCollection  { return _valueList; }
		public static function literalsExtended(firstChoice:String):ArrayCollection {
			var ret:ArrayCollection = new ArrayCollection();
			ret.addItem(firstChoice);
			ret.addAll(_literals);
			return ret;
		}
	}
}